/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var now = new Date();
var thisYear = now.getFullYear();
var thisMonth = now.getMonth() + 1;
var thisQuarter=parseInt((thisMonth-1)/3)+1;
var thisDay = now.getDate();

var yestoday = new Date().add(Date.DAY,-1);

var lastMonth = new Date().add(Date.MONTH,-1);
var lastMonthYear = lastMonth.getFullYear();
var lastMonthMonth = lastMonth.getMonth() + 1;

var years = new Array();
for (var i = 0; i < 10; i++) {
    years[i] = new Array();
    years[i][0] = thisYear - i;
}
;
var yearsStore = new Ext.data.SimpleStore({
    fields: ['year'],
    data: years
});

var lblYear = {xtype:"label",text:'年'};
var lblMonth={xtype:"label",text:'月'};
var lblQuarter={xtype:'label',text:'季度'};
var lblTo = {xtype:'label',text:'至'};

var yearFromCombo = {
    xtype: 'combo',
    store: yearsStore,
    displayField: 'year',
    valueField: 'year',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    fieldLabel: 'Make',
    width: 80,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: lastMonthYear,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.yearFrom = this.getValue();
        }
    }
};
var yearToCombo = {
    xtype: 'combo',
    store: yearsStore,
    displayField: 'year',
    id:'YearToCombo',
    valueField: 'year',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    fieldLabel: 'Make',
    width: 80,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: thisYear,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.yearTo = this.getValue();
        }
    }
};

var months = [['01'], ['02'], ['03'], ['04'], ['05'], ['06'], ['07'], ['08'], ['09'], ['10'], ['11'], ['12']];
var monthsStore = new Ext.data.SimpleStore({
    fields: ['month'],
    data: months
});

var monthFromCombo = {
    xtype: 'combo',
    store: monthsStore,
    displayField: 'month',
    valueField: 'month',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    width: 60,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: lastMonthMonth,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.monthFrom = this.getValue();
        }
    }
};

var monthToCombo = {
    xtype: 'combo',
    id:'MonthToCombo',
    store: monthsStore,
    displayField: 'month',
    valueField: 'month',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    width: 60,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: thisMonth,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.monthTo = this.getValue();
        }
    }
};

var quarters = [[1], [2], [3], [4]];
var quarterStore = new Ext.data.SimpleStore({
    fields: ['quarter'],
    data: quarters
});

var quarterFromCombo = {
    xtype: 'combo',
    store: quarterStore,
    displayField: 'quarter',
    valueField: 'quarter',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    width: 60,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: thisQuarter,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.quarterFrom = this.getValue();
        }
    }
};

var quarterToCombo = {
    xtype: 'combo',
    store: quarterStore,
    displayField: 'quarter',
    valueField: 'quarter',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    width: 60,
    selectOnFocus: true,
    style: {marginLeft: '0px'},
    value: thisQuarter,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.quarterTo = this.getValue();
        }
    }
};

var dateFromField = {
    xtype: 'datefield',
    id: 'dateFrom',
    format: 'Y年m月d日',
    width: 150,
    value: now.add(Date.MONTH, -1),
    listeners: {
        select: function(c, date) {
            store.baseParams.dateFrom = date.format('Ymd');
        }
    }
};

var dateToField = {
    xtype: 'datefield',    
    format: 'Y年m月d日',
    width: 150,
    id:'dateTo',
    value: yestoday,
    listeners: {
        select: function(c, date) {
            store.baseParams.dateTo = date.format('Ymd');
        }
    }
};

